<template>
	<el-card shadow="hover" style="height: 500px; margin-top: 10px; width: 100%; margin-left: 10px; overflow: scroll">
		<el-form
			ref="dialogForm"
			:model="form"
			:rules="rules"
			:disabled="mode == 'show'"
			label-width="100px"
			label-position="left"
		>
			<el-form-item label="应用名称" prop="roleName">
				<el-input v-model="form.appName" clearable></el-input>
			</el-form-item>
			<el-form-item label="应用ID" prop="roleCode">
				<el-input v-model="form.appId" clearable></el-input>
			</el-form-item>
			<el-form-item label="应用类型" prop="meta.type">
				<el-radio-group v-model="form.appType">
					<el-radio-button :label="0">移动H5应用</el-radio-button>
					<el-radio-button :label="1">移动APP应用</el-radio-button>
					<el-radio-button :label="2">PCH5应用</el-radio-button>
				</el-radio-group>
			</el-form-item>
		</el-form>
	</el-card>
	<div
		style="width: 100%; height: 70px; position: absolute; bottom: 0; border-top: 0px solid #e8e8e8; padding-top: 10px"
	>
		<el-button style="margin-left: 30px" @click="visible = false">取 消</el-button>
		<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
	</div>
</template>

<script>
export default {
	emits: ['success', 'closed'],

	data() {
		return {
			mode: 'add',
			titleMap: {
				add: '新增',
				edit: '编辑',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			//表单数据
			form: {
				appName: '',
				appId: '',
				appType: '',
				appSecret: ''
			},
			//验证规则
			rules: {
				sort: [{ required: true, message: '请输入排序', trigger: 'change' }],
				label: [{ required: true, message: '请输入应用名称' }]
			},
			groups: [],
			groupsProps: {
				value: 'id',
				emitPath: false,
				checkStrictly: true
			}
		}
	},
	mounted() {},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode
			this.visible = true
			return this
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true
					var res = await this.$API.basic.app.add.post({ data: this.form })
					this.isSaveing = false
					if (res && res.code == 0) {
						this.$emit('success', this.form, this.mode)
						this.visible = false
						this.$emit('guanbi')
						this.$message.success('操作成功')
					}
				}
			})
		}
	}
}
</script>

<style></style>
